/*
*Copyright 2021-2023 NERCIS
*
*Licensed under the Apache License, Version 2.0 (the "License");
*you may not use this file except in compliance with the License.
*You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*Unless required by applicable law or agreed to in writing, software
*distributed under the License is distributed on an "AS IS" BASIS,
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*See the License for the specific language governing permissions and
*limitations under the License.
*/

package cn.ac.nercis.pes.community.component.controls;

import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;

/**
 * 自定义块按钮
 * @author zpy
 * @version 1.0
 */
public class PesBlockButton extends Button {
    private Node iconGraphic;
    private Button iconBtn;

    public PesBlockButton(){
        this.getStyleClass().add("pes-block-button");
    }

    public void initialize(Node iconGraphic){
        this.iconGraphic = iconGraphic;
        setGraphic(customGraphic());
        setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
    }

    private Node customGraphic(){
        VBox box =new VBox();
        box.setSpacing(5);
        box.getStyleClass().add("pes-block-btn-container");
        iconBtn = new Button();
        iconBtn.getStyleClass().add("btn-icon");
        iconBtn.setGraphic(iconGraphic);
        iconBtn.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
        Label txtBtn = new Label();
        txtBtn.getStyleClass().add("btn-txt");
        txtBtn.textProperty().bind(this.textProperty());
        box.getChildren().addAll(iconBtn,txtBtn);
        return box;
    }

    public void setIconGraphic(Node iconGraphic){
        this.iconGraphic = iconGraphic;
        iconBtn.setGraphic(iconGraphic);
    }
}